package com.diankangwo.factory.controller;

import com.diankangwo.common.utils.PageUtils;
import com.diankangwo.common.utils.Query;
import com.diankangwo.common.utils.R;
import com.diankangwo.factory.annotation.LoginUser2;
import com.diankangwo.factory.entity.TdAccount;
import com.diankangwo.factory.service.TdAccountService;
import com.diankangwo.sys.entity.SysUserEntity;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 结算订单
 */
@RestController
@RequestMapping("/fac/account")
public class TdAccountController {
    @Autowired
    private TdAccountService tdAccountService;

    /**
     * 获取结算账单列表
     */
    @ApiOperation(value = "获取厂家列表", notes = "")
    @ApiImplicitParam(name = "params", value = "查询条件", required = true, dataType = "Map<String,Object>")
    @RequestMapping("/list")
    @RequiresPermissions("fac:account:list")
    public R list(@RequestParam Map<String, Object> params, @LoginUser2 SysUserEntity sysUserEntity, int factoryId) {
        params.put("params", factoryId);
        Query query = new Query(params);
        List<TdAccount> tdAccountList = tdAccountService.queryList(query);
        int total = tdAccountService.queryTotal(query);
        PageUtils pageUtil = new PageUtils(tdAccountList, total, query.getLimit(), query.getPage());
        return R.ok().put("page", pageUtil);
    }

    /**
     * 修改账单状态
     */
    @ApiOperation(value = "修改账单状态", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "账单ID", required = true, dataType = "Integer"),
    })

    @RequestMapping("/update")
    @RequiresPermissions("fac:account:update")
    public R update(@LoginUser2 SysUserEntity sysUserEntity, int id) {
        TdAccount tdAccount = tdAccountService.selectByPrimaryKey(id);
        tdAccount.setUpdatedate(new Date());
        tdAccount.setState(true);
        tdAccount.setUpdateuser(sysUserEntity.getUsername());
        tdAccountService.updateByPrimaryKey(tdAccount);
        return R.ok();
    }
}
